﻿DECLARE @alter NVARCHAR(MAX)
IF  EXISTS (SELECT * FROM sys.views WHERE object_id = OBJECT_ID(N'[dbo].[vw_medianamik_UrlXmlDoc]'))
BEGIN
	SELECT @alter = '
ALTER VIEW [dbo].[vw_medianamik_UrlXmlDoc]
AS
WITH Node AS (SELECT     npv1.NodeId, n.TypeId, npv1.CultureName, npv1.Revision, CAST(npv1.Value AS xml) AS Xml, 
                                                         CASE WHEN npv1.Revision IS NULL THEN - 1 ELSE COUNT(npv2.Revision) - 1 END AS Generation
                                  FROM         dbo.medianamik_NodePropertyValue AS npv1 INNER JOIN
                                                         dbo.medianamik_Node AS n ON n.NodeId = npv1.NodeId INNER JOIN
                                                         dbo.medianamik_Property AS p ON p.PropertyId = npv1.PropertyId INNER JOIN
                                                         dbo.medianamik_NodeInstance AS ni ON ni.NodeId = npv1.NodeId AND ni.CultureName = npv1.CultureName LEFT OUTER JOIN
                                                         dbo.medianamik_NodePropertyValue AS npv2 ON p.PropertyId = npv2.PropertyId AND npv1.NodeId = npv2.NodeId AND 
                                                         npv1.CultureName = npv2.CultureName
                                  WHERE     (p.Name = ''url'') AND (n.IsDeleted = 0) AND (ni.IsActive = 1) AND (ISNULL(npv2.Revision, dbo.fn_medianamik_MaxRevision()) >= ISNULL(npv1.Revision, 
                                                         dbo.fn_medianamik_MaxRevision()))
                                  GROUP BY npv1.NodeId, n.TypeId, npv1.CultureName, npv1.Revision, npv1.Value)
    SELECT     NodeId, TypeId, CultureName, Revision, Xml, Generation
     FROM         Node AS Node_1
     WHERE     (Generation <= 0)'
     	EXEC sp_executesql @alter
END

ALTER TABLE medianamik_MedianamikControl ALTER COLUMN DefaultWidth VARCHAR(10) 
UPDATE medianamik_MedianamikControl SET DefaultWidth = '90%', DefaultHeight = 500 WHERE MedianamikControlID = '9199ad59-e2df-4d53-b404-3f8d612bccb5'

-- EnableMultiLanguageFeatures
IF NOT EXISTS( SELECT NULL FROM medianamik_Property where PropertyId = 'FDA53EB7-90EA-425C-BFB6-8352D4964281' )  BEGIN  INSERT INTO [dbo].[medianamik_Property]             ([PropertyId]             ,[TypeId]             ,[Name]             ,[HaveTooltip]             ,[IsLanguageNeutral]             ,[IsRequired]             ,[IsUnique]             ,[ValidationRegex]             ,[GroupName]             ,[Flags]             ,[MedianamikControlId]             ,[MedianamikControlWidth]             ,[MedianamikControlHeight]             ,[Position]             ,[PrimaryPropertyId]             ,[PrimaryTypeId]             ,[PrimaryMedianamikControlId]             ,[PrimaryMedianamikControlWidth]             ,[PrimaryMedianamikControlHeight]             ,[Roles]             ,[MaxLength]             ,[MinLength]             ,[DataTypeId]             ,[PrimaryDataTypeId]             ,[Description]             ,[TreeRootNodeId]             , [PrimaryTreeRootNodeId])       VALUES             ('FDA53EB7-90EA-425C-BFB6-8352D4964281'             ,'45C90CDA-E48D-4F9E-A5A4-1C398B9DD5F5'     , 'EnableMultiLanguageFeatures'     ,         0     ,         1     ,         0     ,         0     ,NULL     ,''     ,         0     ,'8115FD40-5BEB-434F-ABB2-4F46FB29B86E'     ,null     ,null     ,         0     ,NULL     ,NULL     ,NULL     ,null     ,null     ,''     ,NULL     ,NULL     ,'E7293D5E-0B55-4FF1-A24A-B4969B187A19'     ,'0D5B7A19-A12A-46B5-9A2C-8D15093F5666'     ,'Enable Multilanguage Features'     ,NULL              ,NULL             )  END

--CultureSelectorWindow.aspx
IF NOT EXISTS( SELECT NULL  FROM medianamik_Node where NodeId = '54CB4BEF-B56F-4F58-BB2E-0225106B5C48')  BEGIN  INSERT INTO [dbo].[medianamik_Node]             ([NodeId]             ,[ParentNodeId]             ,[TypeId]             ,[CreatedOn]             ,[CreatedBy]             ,[ModifiedOn]             ,[ModifiedBy]             ,[Flags]             ,[IsDeleted]             ,[Path]             ,[Depth]             ,[Position]             ,[EditedOn]             ,[EditedBy])       VALUES             ('54CB4BEF-B56F-4F58-BB2E-0225106B5C48'             ,'7A6A4803-1D66-40F5-8DAB-76AFDAE93CF0'                        ,'3DAD4D08-B9BC-4603-A8DE-42A88A354B5B'             ,'2009-05-15 10:32:14.900'             ,''             ,'2009-05-15 10:32:14.900'             ,''             ,         0             ,         0             ,'.7A6A4803-1D66-40F5-8DAB-76AFDAE93CF0.54CB4BEF-B56F-4F58-BB2E-0225106B5C48.'             ,         1             ,         0             ,'2009-05-15 10:32:14.900'             ,'sa'             )  END
IF NOT EXISTS(SELECT NULL FROM Medianamik_NodeInstance WHERE NodeId = '54CB4BEF-B56F-4F58-BB2E-0225106B5C48' AND CultureNAme = 'en-CA')  BEGIN  INSERT INTO [dbo].[medianamik_NodeInstance]             ([NodeInstanceId]             ,[NodeId]             ,[IsActive]             ,[CreatedOn]             ,[CultureName])       VALUES             ('C9BB3503-B66D-47E6-8260-64A7E858F1EE'             ,'54CB4BEF-B56F-4F58-BB2E-0225106B5C48'             ,         1             ,'2009-05-15 10:32:14.900'             ,'en-CA')  END
IF NOT EXISTS(SELECT NULL FROM Medianamik_NodeInstance WHERE NodeId = '54CB4BEF-B56F-4F58-BB2E-0225106B5C48' AND CultureNAme = 'fr-CA')  BEGIN  INSERT INTO [dbo].[medianamik_NodeInstance]             ([NodeInstanceId]             ,[NodeId]             ,[IsActive]             ,[CreatedOn]             ,[CultureName])       VALUES             ('FEE646F1-C0D6-4A5A-A4ED-F61CB30E00CE'             ,'54CB4BEF-B56F-4F58-BB2E-0225106B5C48'             ,         1             ,'2009-05-15 10:32:14.900'             ,'fr-CA')  END
IF NOT EXISTS( SELECT NULL FROM medianamik_NodePropertyValue where NodeId = '54CB4BEF-B56F-4F58-BB2E-0225106B5C48' AND PropertyId = '60C0AA24-C355-4722-ACAA-21D363351479' AND CultureName = '' AND Revision IS NULL)  BEGIN  INSERT INTO [dbo].[medianamik_NodePropertyValue]             ([NodeId]             ,[PropertyId]             ,[Value]             ,[Revision]             ,[CultureName]             ,[EndRevision]             )       VALUES             ('54CB4BEF-B56F-4F58-BB2E-0225106B5C48'             ,'60C0AA24-C355-4722-ACAA-21D363351479'             ,NULL                       ,null             ,''             ,null             )  END
IF NOT EXISTS( SELECT NULL FROM medianamik_NodePropertyValue where NodeId = '54CB4BEF-B56F-4F58-BB2E-0225106B5C48' AND PropertyId = 'A5F1D87F-3086-4CEA-A983-A09D4FE9FC4C' AND CultureName = '' AND Revision IS NULL)  BEGIN  INSERT INTO [dbo].[medianamik_NodePropertyValue]             ([NodeId]             ,[PropertyId]             ,[Value]             ,[Revision]             ,[CultureName]             ,[EndRevision]             )       VALUES             ('54CB4BEF-B56F-4F58-BB2E-0225106B5C48'             ,'A5F1D87F-3086-4CEA-A983-A09D4FE9FC4C'             ,NULL                       ,null             ,''             ,null             )  END
IF NOT EXISTS( SELECT NULL FROM medianamik_NodePropertyValue where NodeId = '54CB4BEF-B56F-4F58-BB2E-0225106B5C48' AND PropertyId = '7213C44C-BBC7-4095-AE52-0DE37E7276C7' AND CultureName = '' AND Revision IS NULL)  BEGIN  INSERT INTO [dbo].[medianamik_NodePropertyValue]             ([NodeId]             ,[PropertyId]             ,[Value]             ,[Revision]             ,[CultureName]             ,[EndRevision]             )       VALUES             ('54CB4BEF-B56F-4F58-BB2E-0225106B5C48'             ,'7213C44C-BBC7-4095-AE52-0DE37E7276C7'             ,'False'                       ,null             ,''             ,null             )  END
IF NOT EXISTS( SELECT NULL FROM medianamik_NodePropertyValue where NodeId = '54CB4BEF-B56F-4F58-BB2E-0225106B5C48' AND PropertyId = '47096ACE-4C51-4C8F-BAE2-15A6FD90F6E9' AND CultureName = '' AND Revision IS NULL)  BEGIN  INSERT INTO [dbo].[medianamik_NodePropertyValue]             ([NodeId]             ,[PropertyId]             ,[Value]             ,[Revision]             ,[CultureName]             ,[EndRevision]             )       VALUES             ('54CB4BEF-B56F-4F58-BB2E-0225106B5C48'             ,'47096ACE-4C51-4C8F-BAE2-15A6FD90F6E9'             ,'/modalwindows/CultureSelectorWindow.aspx'                       ,null             ,''             ,null             )  END
IF NOT EXISTS( SELECT NULL FROM medianamik_NodePropertyValue where NodeId = '54CB4BEF-B56F-4F58-BB2E-0225106B5C48' AND PropertyId = 'A9D96D60-4E0D-4EF6-831C-AAD02A1D2BCF' AND CultureName = '' AND Revision IS NULL)  BEGIN  INSERT INTO [dbo].[medianamik_NodePropertyValue]             ([NodeId]             ,[PropertyId]             ,[Value]             ,[Revision]             ,[CultureName]             ,[EndRevision]             )       VALUES             ('54CB4BEF-B56F-4F58-BB2E-0225106B5C48'             ,'A9D96D60-4E0D-4EF6-831C-AAD02A1D2BCF'             ,'False'                       ,null             ,''             ,null             )  END
IF NOT EXISTS( SELECT NULL FROM medianamik_NodePropertyValue where NodeId = '54CB4BEF-B56F-4F58-BB2E-0225106B5C48' AND PropertyId = '29571C7C-3B7A-4576-8BB0-F2EAF8413D20' AND CultureName = '' AND Revision IS NULL)  BEGIN  INSERT INTO [dbo].[medianamik_NodePropertyValue]             ([NodeId]             ,[PropertyId]             ,[Value]             ,[Revision]             ,[CultureName]             ,[EndRevision]             )       VALUES             ('54CB4BEF-B56F-4F58-BB2E-0225106B5C48'             ,'29571C7C-3B7A-4576-8BB0-F2EAF8413D20'             ,'False'                       ,null             ,''             ,null             )  END
IF NOT EXISTS( SELECT NULL FROM medianamik_NodePropertyValue where NodeId = '54CB4BEF-B56F-4F58-BB2E-0225106B5C48' AND PropertyId = '18232ABC-5DD8-4AE5-947A-16F3AF3A8715' AND CultureName = 'fr-CA' AND Revision IS NULL)  BEGIN  INSERT INTO [dbo].[medianamik_NodePropertyValue]             ([NodeId]             ,[PropertyId]             ,[Value]             ,[Revision]             ,[CultureName]             ,[EndRevision]             )       VALUES             ('54CB4BEF-B56F-4F58-BB2E-0225106B5C48'             ,'18232ABC-5DD8-4AE5-947A-16F3AF3A8715'             ,'Sélection d''une langue'                       ,null             ,'fr-CA'             ,null             )  END
IF NOT EXISTS( SELECT NULL FROM medianamik_NodePropertyValue where NodeId = '54CB4BEF-B56F-4F58-BB2E-0225106B5C48' AND PropertyId = '18232ABC-5DD8-4AE5-947A-16F3AF3A8715' AND CultureName = 'en-CA' AND Revision IS NULL)  BEGIN  INSERT INTO [dbo].[medianamik_NodePropertyValue]             ([NodeId]             ,[PropertyId]             ,[Value]             ,[Revision]             ,[CultureName]             ,[EndRevision]             )       VALUES             ('54CB4BEF-B56F-4F58-BB2E-0225106B5C48'             ,'18232ABC-5DD8-4AE5-947A-16F3AF3A8715'             ,'Language Selection'                       ,null             ,'en-CA'             ,null             )  END

--Ajout de la propriete ishttps au type MedianamikPageTemplate
IF NOT EXISTS( SELECT NULL  FROM medianamik_Type where TypeId = '0D9D1AA8-2C70-4402-ABD1-6CC028024967')  BEGIN  INSERT INTO [dbo].[medianamik_Type]             ([TypeId]             ,[ParentTypeId]             ,[Name]             ,[CanHaveChilds]             ,[IsGenerated]             ,[IsManyToMany]             ,[Path]             ,[Depth]             ,[Roles]             ,[Flags]             ,[Description]             ,[ExtendedProperties]             ,[IsSystem]             ,[IsAbstract])       VALUES             ('0D9D1AA8-2C70-4402-ABD1-6CC028024967'             ,'0F97D80D-1B34-417D-AB7A-0C8C459A8146'             ,'MedianamikPageTemplate'             ,         0             ,         0             ,         0             ,'.0F97D80D-1B34-417D-AB7A-0C8C459A8146.0D9D1AA8-2C70-4402-ABD1-6CC028024967.'             ,         1     ,NULL     ,         0             ,''     ,'<ExtendedProperties><ClientTemplatePaths/><Icon/><PropertyPositions/></ExtendedProperties>'            ,         1     ,         0             )  END
IF NOT EXISTS( SELECT NULL FROM medianamik_Property where PropertyId = '09285C1B-B776-4265-875A-5F9800CA950B' )  BEGIN  INSERT INTO [dbo].[medianamik_Property]             ([PropertyId]             ,[TypeId]             ,[Name]             ,[HaveTooltip]             ,[IsLanguageNeutral]             ,[IsRequired]             ,[IsUnique]             ,[ValidationRegex]             ,[GroupName]             ,[Flags]             ,[MedianamikControlId]             ,[MedianamikControlWidth]             ,[MedianamikControlHeight]             ,[Position]             ,[PrimaryPropertyId]             ,[PrimaryTypeId]             ,[PrimaryMedianamikControlId]             ,[PrimaryMedianamikControlWidth]             ,[PrimaryMedianamikControlHeight]             ,[Roles]             ,[MaxLength]             ,[MinLength]             ,[DataTypeId]             ,[PrimaryDataTypeId]             ,[Description]             ,[TreeRootNodeId]             , [PrimaryTreeRootNodeId])       VALUES             ('09285C1B-B776-4265-875A-5F9800CA950B'             ,'0D9D1AA8-2C70-4402-ABD1-6CC028024967'     , 'Name'     ,         0     ,         0     ,         1     ,         1     ,NULL     ,''     ,         1     ,'7E4BA709-965E-42DD-92B8-028DDCED0D7C'     ,'250px'     ,null     ,         0     ,NULL     ,NULL     ,NULL     ,null     ,null     ,''     ,        50     ,NULL     ,'195F6F67-F42D-428B-BE3E-AD8762CDE76F'     ,'0D5B7A19-A12A-46B5-9A2C-8D15093F5666'     ,''     ,NULL              ,NULL             )  END
IF NOT EXISTS( SELECT NULL FROM medianamik_Property where PropertyId = '4BB3FFBA-AC89-4206-8697-BE4CB58190D5' )  BEGIN  INSERT INTO [dbo].[medianamik_Property]             ([PropertyId]             ,[TypeId]             ,[Name]             ,[HaveTooltip]             ,[IsLanguageNeutral]             ,[IsRequired]             ,[IsUnique]             ,[ValidationRegex]             ,[GroupName]             ,[Flags]             ,[MedianamikControlId]             ,[MedianamikControlWidth]             ,[MedianamikControlHeight]             ,[Position]             ,[PrimaryPropertyId]             ,[PrimaryTypeId]             ,[PrimaryMedianamikControlId]             ,[PrimaryMedianamikControlWidth]             ,[PrimaryMedianamikControlHeight]             ,[Roles]             ,[MaxLength]             ,[MinLength]             ,[DataTypeId]             ,[PrimaryDataTypeId]             ,[Description]             ,[TreeRootNodeId]             , [PrimaryTreeRootNodeId])       VALUES             ('4BB3FFBA-AC89-4206-8697-BE4CB58190D5'             ,'0D9D1AA8-2C70-4402-ABD1-6CC028024967'     , 'Path'     ,         0     ,         1     ,         1     ,         1     ,NULL     ,''     ,         1     ,'7E4BA709-965E-42DD-92B8-028DDCED0D7C'     ,'250px'     ,null     ,         0     ,NULL     ,NULL     ,NULL     ,null     ,null     ,''     ,       255     ,NULL     ,'195F6F67-F42D-428B-BE3E-AD8762CDE76F'     ,'0D5B7A19-A12A-46B5-9A2C-8D15093F5666'     ,''     ,NULL              ,NULL             )  END
IF NOT EXISTS( SELECT NULL FROM medianamik_Property where PropertyId = 'DF5A365E-D598-4078-A405-B6CC12FE0ABD' )  BEGIN  INSERT INTO [dbo].[medianamik_Property]             ([PropertyId]             ,[TypeId]             ,[Name]             ,[HaveTooltip]             ,[IsLanguageNeutral]             ,[IsRequired]             ,[IsUnique]             ,[ValidationRegex]             ,[GroupName]             ,[Flags]             ,[MedianamikControlId]             ,[MedianamikControlWidth]             ,[MedianamikControlHeight]             ,[Position]             ,[PrimaryPropertyId]             ,[PrimaryTypeId]             ,[PrimaryMedianamikControlId]             ,[PrimaryMedianamikControlWidth]             ,[PrimaryMedianamikControlHeight]             ,[Roles]             ,[MaxLength]             ,[MinLength]             ,[DataTypeId]             ,[PrimaryDataTypeId]             ,[Description]             ,[TreeRootNodeId]             , [PrimaryTreeRootNodeId])       VALUES             ('DF5A365E-D598-4078-A405-B6CC12FE0ABD'             ,'0D9D1AA8-2C70-4402-ABD1-6CC028024967'     , 'IsHttps'     ,         0     ,         1     ,         0     ,         0     ,NULL     ,''     ,         0     ,'1C4380C3-1D80-46FC-9E2F-D7A9D14E54D7'     ,null     ,null     ,         0     ,NULL     ,NULL     ,NULL     ,null     ,null     ,''     ,NULL     ,NULL     ,'E7293D5E-0B55-4FF1-A24A-B4969B187A19'     ,'0D5B7A19-A12A-46B5-9A2C-8D15093F5666'     ,''     ,NULL              ,NULL             )  END
if not exists(select typeId from [medianamik_HierarchicalRule] where TypeId = '0D9D1AA8-2C70-4402-ABD1-6CC028024967' and ParentItemId = '7A6A4803-1D66-40F5-8DAB-76AFDAE93CF0')   begin    INSERT INTO [dbo].[medianamik_HierarchicalRule]         ([HierarchicalRuleId]         ,[TypeId]         ,[ParentItemId]         ,[ParentItemType])      VALUES         ('BA341B7A-7D04-41D7-AD54-575BD659BB26'         ,'0D9D1AA8-2C70-4402-ABD1-6CC028024967'         ,'7A6A4803-1D66-40F5-8DAB-76AFDAE93CF0'         ,1)     end
if not exists(select typeId from [medianamik_HierarchicalRule] where TypeId = '0D9D1AA8-2C70-4402-ABD1-6CC028024967' and ParentItemId = '627E47FC-6C91-444F-B3A6-79B1F687EF9A')   begin    INSERT INTO [dbo].[medianamik_HierarchicalRule]         ([HierarchicalRuleId]         ,[TypeId]         ,[ParentItemId]         ,[ParentItemType])      VALUES         ('490AD2AD-C79F-4882-84B5-CEFCE6A0D664'         ,'0D9D1AA8-2C70-4402-ABD1-6CC028024967'         ,'627E47FC-6C91-444F-B3A6-79B1F687EF9A'         ,0)     end


--Supression de la propriété IsHttps du BaseWebType
if exists( select null from medianamik_Property where PropertyId = 'C45B2987-344A-4A68-8637-32A1ECDEF34F' )  BEGIN delete from [dbo].[medianamik_Property]  where propertyid = 'C45B2987-344A-4A68-8637-32A1ECDEF34F' end

-- Correction d'une mauvaise image de menu pour la configuration
UPDATE medianamik_NodePropertyValue SET Value = '/Medianamik/images/Icones/Ico_AccGestionConfiguration.png' WHERE PropertyId = '777e535e-66e6-4cb4-a066-c200d4b9c5e0' AND NodeId = 'eede521a-746e-4943-843e-80f54d884824'